from tortoise import BaseDBAsyncClient


async def upgrade(db: BaseDBAsyncClient) -> str:
    return """
        ALTER TABLE "device" ADD "is_active" BOOL NOT NULL DEFAULT True;
        ALTER TABLE "device" ALTER COLUMN "rack_location" TYPE VARCHAR(100) USING "rack_location"::VARCHAR(100);
        CREATE INDEX IF NOT EXISTS "idx_device_device__9afeac" ON "device" ("device_group_id", "status");
        CREATE INDEX IF NOT EXISTS "idx_device_area_id_903a1d" ON "device" ("area_id", "status");
        CREATE INDEX IF NOT EXISTS "idx_device_brand_i_c29865" ON "device" ("brand_id", "status");
        CREATE INDEX IF NOT EXISTS "idx_device_is_acti_3f5e22" ON "device" ("is_active");"""


async def downgrade(db: BaseDBAsyncClient) -> str:
    return """
        DROP INDEX IF EXISTS "idx_device_is_acti_3f5e22";
        DROP INDEX IF EXISTS "idx_device_brand_i_c29865";
        DROP INDEX IF EXISTS "idx_device_area_id_903a1d";
        DROP INDEX IF EXISTS "idx_device_device__9afeac";
        ALTER TABLE "device" DROP COLUMN "is_active";
        ALTER TABLE "device" ALTER COLUMN "rack_location" TYPE VARCHAR(200) USING "rack_location"::VARCHAR(200);"""
